<?php 

class AttrController extends Controller{
	public $model;
	public function __init(){
		$this->model = K('typeattr');
	}
	/**
	 * 属性列表
	 */
	public function index(){
	   $tid = Q("get.tid");
	   $data = $this->model->where("tid=$tid")->select();
	   $this->assign("data",$data);
       $this->display();
	}
	/**
	 * 添加属性
	 */
	 public function add(){
	 	if(IS_POST){
			if(!$this->model->addData()){
				$this->error($this->model->error);
			}
			$this->success("添加属性成功");
	 	}
	     $this->display();
	 }
	 /**
	 * 删除属性
	 */
	 public function del(){
	     $attrid = Q("get.attrid");
		 if(!$this->model->where("attrid=$attrid")->delete()){
		 	$this->error($model->error);
		 }
		 $this->success("删除属性成功",U("Type/index"));
	 }
	 /**
	 * 编辑属性
	 */
	 public function edit(){
	 	 $attrid = Q("get.attrid");
		 if(IS_POST){
		 	if(!$this->model->editData($attrid)){
		 		$this->error($model->error);
		 	}
			$this->success("修改成功",U("Type/index"));
		 }
		 $data = $this->model->where("attrid=$attrid")->find();
		 $this->assign("data",$data);
	     $this->display();
	 }
}